package cn.edu.baiyunu.myapplication.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Crop
import androidx.compose.material.icons.filled.Download
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material.icons.filled.AutoFixHigh
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import cn.edu.baiyunu.myapplication.ui.home.HomeViewModel

/**
 * 特点卡片组件
 */
@Composable
fun FeatureCard(
    feature: HomeViewModel.Feature,
    modifier: Modifier = Modifier
) {
    // 根据特点名称选择对应的图标
    val icon = when (feature.iconName) {
        "magic" -> Icons.Default.AutoFixHigh
        "crop-alt" -> Icons.Default.Crop
        "download" -> Icons.Default.Download
        "shield-alt" -> Icons.Default.Lock
        else -> Icons.Default.AutoFixHigh
    }
    
    // 根据特点名称选择不同的颜色
    val colors = when (feature.iconName) {
        "magic" -> listOf(Color(0xFFF0F7FF), Color(0xFFE6F0FF))
        "crop-alt" -> listOf(Color(0xFFF5F0FF), Color(0xFFEEE6FF))
        "download" -> listOf(Color(0xFFFFF7E6), Color(0xFFFFEFCC))
        "shield-alt" -> listOf(Color(0xFFF0F7FF), Color(0xFFE6F0FF))
        else -> listOf(Color(0xFFF0F7FF), Color(0xFFE6F0FF))
    }
    
    Card(
        modifier = modifier
            .fillMaxWidth()
            .padding(4.dp),
        shape = RoundedCornerShape(12.dp),
        elevation = CardDefaults.cardElevation(defaultElevation = 0.dp),
        colors = CardDefaults.cardColors(
            containerColor = MaterialTheme.colorScheme.surface
        )
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .padding(16.dp)
        ) {
            // 图标
            Box(
                modifier = Modifier
                    .size(48.dp)
                    .clip(RoundedCornerShape(12.dp))
                    .background(
                        brush = Brush.linearGradient(colors)
                    )
                    .padding(12.dp),
                contentAlignment = Alignment.Center
            ) {
                Icon(
                    imageVector = icon,
                    contentDescription = feature.title,
                    tint = MaterialTheme.colorScheme.primary,
                    modifier = Modifier.size(24.dp)
                )
            }
            
            // 标题
            Text(
                text = feature.title,
                style = MaterialTheme.typography.titleMedium,
                fontWeight = FontWeight.SemiBold,
                color = MaterialTheme.colorScheme.onSurface,
                modifier = Modifier.padding(top = 12.dp)
            )
            
            // 描述
            Text(
                text = feature.description,
                style = MaterialTheme.typography.bodySmall,
                color = MaterialTheme.colorScheme.onSurfaceVariant,
                modifier = Modifier.padding(top = 4.dp)
            )
        }
    }
} 